
define(['angular' ,'jquery' ,'common','uiBootstrap','treeView' ],function(angular,$,common){
	var services = angular.module('app.apiservices', ['ui.bootstrap','app.treeView']);
		console.log('API调用服务apiservices被加载！');
//	console.log('services-->',services);
	
    'use strict';

    services.factory('apiService',['$rootScope', '$uibModal'
    	,function ($rootScope, $uibModal){
    	
		var _self = this;
		
		
		//打开对话框（选择快递公司）
		var openExpressCodeDialog = function(options){

	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: '',
	            templateUrl: 'js/_services_api/tpl/selectExpress/selectSingle.html',  
	            controller: 'expressInfoSelectSingleCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
//                    ,loadCtrl : $ocLazyLoad.load('js/common/expressInfo/selectSingle.js')
		        }
	        });  
	        return dlg;
		};
		
		//打开对话框（选择地址信息）
		var openRegionCodeDialog = function(options){

	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: '',
	            templateUrl: 'js/_services_api/tpl/selectRegion/selectSingle.html',  
	            controller: 'regionInfoSelectSingleCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
//                    ,loadCtrl : $ocLazyLoad.load('js/common/regionInfo/selectSingle.js')
		        }
	        });  
	        return dlg;
		};
		

		//打开对话框（选择公海人员信息）
		var openPersonCodeDialog = function(options){

	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: '',
	            templateUrl: 'js/_services_api/tpl/selectPerson/selectSingle.html',  
	            controller: 'personSelectSingleCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
//                    ,loadCtrl : $ocLazyLoad.load('js/common/selectPerson/selectSingle.js')
		        }
	        });  
	        return dlg;
		};
		
		//打开对话框（选择顶级组织）公司
		var openOgnNoDialog = function(options){

	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: '',
	            templateUrl: 'js/_services_api/tpl/selectOgn/selectSingle.html',  
	            controller: 'ognSelectSingleCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
//                    ,loadCtrl : $ocLazyLoad.load('js/common/selectOgn/selectSingle.js')
		        }
	        });  
	        return dlg;
		};
		
		//打开对话框（选择隶属于组织人员）经办人
		var openOrgNoDialog = function(options){

	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: '',
	            templateUrl: 'js/_services_api/tpl/selectOrg/selectSingle.html',  
	            controller: 'orgSelectSingleCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
//                    ,loadCtrl : $ocLazyLoad.load('js/common/selectOrg/selectSingle.js')
		        }
	        });  
	        return dlg;
		};
		
		//打开对话框（选择云物料）
		var openCloudItemDialog = function(options){

	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: '',
	            templateUrl: 'js/_services_api/tpl/selectCloudItem/selectMulti.html',  
	            controller: 'cloudItemSelectMultiCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
		        }
	        });  
	        return dlg;
		};
		
		//打开对话框（追踪快递信息）
		var openExpressTrackDialog = function(options){

	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: '',
	            templateUrl: 'js/_services_api/tpl/expressTrack/expressTrack.html',  
	            controller: 'expressTrackMonitorCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '物流信息'; }
//                    ,loadCtrl : $ocLazyLoad.load('js/common/expressTrack/monitor.js')
		        }
	        });  
	        return dlg;
		};

    
		
		return {
			//弹出消息对话框（附带打开单据功能）
			getAppConfigParams: function(){
				return getAppConfigParams();
			},
			//打开对话框（选择快递公司）
			openExpressCodeDialog: function(options){
				return openExpressCodeDialog(options);
			},
			//打开对话框（选择地址信息）
			openRegionCodeDialog: function(options){
				return openRegionCodeDialog(options);
			},
			//打开对话框（选择公海人员信息）
			openPersonCodeDialog: function(options){
				return openPersonCodeDialog(options);
			},
			//打开对话框（选择于组织）
			openOgnNoDialog: function(options){
				return openOgnNoDialog(options);
			},
			//打开对话框（选择隶属于组织）
			openOrgNoDialog: function(options){
				return openOrgNoDialog(options);
			},
			//打开对话框（选择云物料）
			openCloudItemDialog: function(options){
				return openCloudItemDialog(options);
			},
			//打开对话框（快递信息）
			openExpressTrackDialog: function(options){
				return openExpressTrackDialog(options);
			}
			
		};
    
	}])
	.controller('expressInfoSelectSingleCtrl'
		,['$rootScope', '$scope', 'BizData', '$uibModalInstance','params', 'title'
		   , function ($rootScope, $scope, BizData, $uibModalInstance, params, title) {

				var Model = this;

				Model.gridRowClick = function(event){
					
				}

				Model.gridRowDblClick = function(event){
					Model.ok();
				}
				
				
				var options = {};
				options.container = Model;
				options.concept = 'ExpressInfo';
				options.name = 'dataList';
				options.url = $rootScope.path;
//				options.httpUrl = $rootScope.appConfigParams.resourceServer;
				options.httpUrl = $rootScope.getServiceName();
				options.reader = '/remote/expressInfo/list/query';
				options.writer = '';
				options.deleter = '';
				options.idColumnDefine = "fID";
				options.idColumnName = "fID";
				options.isTree = false;
				options.parentRelation = 'fParent';
				options.nodeKindRelation = 'nodeKind';
				options.nodeLevelRelation = 'nodeLevel';
				options.pathRelation = 'fID';
				options.directDeleteMode = true;
				options.limit = 10;
				options.orderBy = 'ExpressInfo.expressCode';
				
				options.onIndexChanging = null;
				options.onIndexChanged = Model.dataListIndexChanged;
				options.onBeforeNew = Model.dataListBeforeNew;
				options.onAfterNew = Model.dataListAfterNew;
				options.onBeforeDelete = Model.dataListBeforeDelete;
				options.onAfterDelete = Model.dataListAfterDelete;
				options.onValueChanged = Model.dataListValueChanged;
				options.onDataChanged = Model.dataListDataChanged;
				
				$scope.dataList = new BizData(options);

				//监视对象中的所有变动
				$scope.dataList.deregRows = $scope.$watch('dataList.rows',$scope.dataList.watchRows,true);//true代表深度监视，包括对象的属性，而不是简单的一个值
				//////////////////////////////////////////////
				
				//////////////////////对话框使用开始//////////////////////////////////////
				
		        //模态窗口打开之后执行的事件
		        $uibModalInstance.opened.then(function(){
		    		//接收调用对话框的参数
		            Model.title = title;  
		            Model.params = params;  
		    		//设置过滤条件
//			    		$scope.dataList.filter = "ExpressInfo.enterpriseNo='"+ Model.params.id 
//			    		+"' AND ExpressInfo.status='open'";

		    		//刷新数据
		    	    $scope.dataList.refreshData();
		        });  
				
		        Model.ok = function () {  
			    	//保存成功
			    	//打包数据
			    	var event = {};
			    	var data = [];
			    	var sourceRow = $scope.dataList.rows[$scope.dataList.currentIndex];
			    	var row = {};
					//循环行中的列，判断变化点是哪一个
					for(var obj in sourceRow){
						if(obj!='$$hashKey' && obj!='userdata'){
							row[obj] = sourceRow[obj].value;
						}
					}
			    	
			    	data.push(row);
			    	event.data = data;
					$uibModalInstance.close(event);  
			    };  
			    
			    Model.cancel = function () {  
			        $uibModalInstance.dismiss('cancel');  
			    };    
				//////////////////////对话框使用结束//////////////////////////////////////
			    


				
				return Model;
			    
			    
			}])//控制器结束

	.controller('regionInfoSelectSingleCtrl'
			,['$rootScope', '$scope', 'BizData', '$uibModalInstance','params', 'title'
			   , function ($rootScope, $scope, BizData, $uibModalInstance, params, title) {


			   		var Model = this;
			   		
			   		Model.groupRowClick = function(event){
//					   			console.log()
			   		};
					
					/**
					name:bizData#onIndexChanged
					description: <b>[回调型事件]</b>行记录变化
					@param {object} event 
					<br/><b>结构如下：</b>
					<xmp> 
					{
						"source" : 组件的js对象,
						"rowID" : 行Id,
						"rowIndex" : 行索引
					}
					</xmp>	
					*/
					Model.dataMasterIndexChanged = function(event) {
						if(event.rowID!=null){
//									$scope.dataTree.fMasterID = event.rowID;
//									$scope.dataTree.rootFilter = "RegionInfo.fParent='"+event.rowID+"'";
							$scope.dataTree.filter = "RegionInfo.regionFullID like'%"+event.rowID+"%'";

				       		$scope.dataTree.refreshData();
						}else{
							$scope.dataTree.clearData();
						}
					};
					
					Model.dataMasterAfterRefresh = function(event) {
						console.log('dataMasterAfterRefresh.event-->>',event);
					};
			   		
			   		//分组数据
			   		var options = {};
					options.container = Model;
					options.concept = 'RegionInfo';
					options.name = 'dataMaster';
					options.url = $rootScope.path;
//					options.httpUrl = $rootScope.appConfigParams.resourceServer;
					options.httpUrl = $rootScope.getServiceName();
			   		options.reader = '/remote/regionInfo/tree/query';
			   		options.writer = '';
			   		options.deleter = '';
			   		options.idColumnDefine = "fID";
			   		options.idColumnName = "fID";
			   		options.isTree = false;
			   		options.parentRelation = 'fParent';
			   		options.nodeKindRelation = 'nodeKind';
			   		options.nodeLevelRelation = 'nodeLevel';
			   		options.nodeSortRelation = "sortNo";
//					options.rootFilter = 'RegionInfo.fParent is null';
//					options.rootFilter = 'RegionInfo.nodeLevel=2';
			   		options.pathRelation = 'regionFullID';
			   		options.directDeleteMode = false;
			   		options.limit = -1;
					options.orderBy = 'sortNo ASC';

					options.onIndexChanged = Model.dataMasterIndexChanged;
					options.onAfterRefresh = Model.dataMasterAfterRefresh;
			   		
			   		$scope.dataMaster = new BizData(options);
			   		//监视对象中的所有变动
			   		$scope.dataMaster.deregRows = $scope.$watch('dataMaster.rows',$scope.dataMaster.watchRows,true);//true代表深度监视，包括对象的属性，而不是简单的一个值

			   		
			   		var options = {};
					options.container = Model;
					options.concept = 'RegionInfo';
					options.name = 'dataTree';
					options.url = $rootScope.path;
//					options.httpUrl = $rootScope.appConfigParams.resourceServer;
					options.httpUrl = $rootScope.getServiceName();
			   		options.reader = '/remote/regionInfo/tree/query';
			   		options.writer = '';
			   		options.deleter = '';
			   		options.idColumnDefine = "fID";
			   		options.idColumnName = "fID";
			   		options.isTree = true;
			   		options.parentRelation = 'fParent';
			   		options.nodeKindRelation = 'nodeKind';
			   		options.nodeLevelRelation = 'nodeLevel';
			   		options.nodeSortRelation = "sortNo";
//					options.rootFilter = 'RegionInfo.fParent is null';
			   		options.rootFilter = 'RegionInfo.nodeLevel=2';
			   		options.pathRelation = 'regionFullID';
			   		options.directDeleteMode = false;
			   		options.limit = -1;
					options.orderBy = 'sortNo ASC';

			   		
			   		$scope.dataTree = new BizData(options);
			   		//监视对象中的所有变动
//					$scope.dataTree.deregRows = $scope.$watch('dataTree.rows',$scope.dataTree.watchRows,true);//true代表深度监视，包括对象的属性，而不是简单的一个值
			   		//////////////////////////////////////////////

					
					
					//////////////////////对话框使用开始//////////////////////////////////////
					
			        //模态窗口打开之后执行的事件
			        $uibModalInstance.opened.then(function(){
			    		//接收调用对话框的参数
			            Model.title = title;  
			            Model.params = params;
			        	//公司
			    		//设置过滤条件
					    $scope.dataMaster.filter = "RegionInfo.fParent is null";
			       		$scope.dataMaster.refreshData();

			        });  
					
			        Model.ok = function () {  
				    	//保存成功
				    	//打包数据
				    	var event = {};
				    	var data = [];
				    	var sourceRow = $scope.dataTree.rows[$scope.dataTree.currentIndex];
				    	var row = {};
						//循环行中的列，判断变化点是哪一个
						for(var obj in sourceRow){
							if(obj!='$$hashKey' && obj!='userdata'){
								row[obj] = sourceRow[obj].value;
							}
						}
				    	
				    	data.push(row);
				    	event.data = data;
						$uibModalInstance.close(event);  
				    };  
				    
				    Model.cancel = function () {  
				        $uibModalInstance.dismiss('cancel');  
				    };    
					//////////////////////对话框使用结束//////////////////////////////////////
				    



				    return Model;
				    
				}])//控制器结束
	.controller('personSelectSingleCtrl'
			,['$rootScope', '$scope', 'BizData', '$uibModalInstance','params', 'title'
			   , function ($rootScope, $scope, BizData, $uibModalInstance, params, title
			   ) {

					var Model = this;

					Model.gridRowClick = function(event){
						
					}

					Model.gridRowDblClick = function(event){
						Model.ok();
					}
					
					var options = {};
					options.container = Model;
					options.concept = 'SaOpperson';
					options.name = 'dataPerson';
					options.url = $rootScope.path;
//					options.httpUrl = $rootScope.appConfigParams.resourceServer;
					options.httpUrl = $rootScope.getServiceName();
					options.reader = '/remote/personInfo/list/query';
					options.writer = '';
					options.deleter = '';
					options.idColumnDefine = "sID";
					options.idColumnName = "sID";
					options.isTree = false;
					options.parentRelation = 'sParent';
					options.nodeKindRelation = 'sNodeKind';
					options.nodeLevelRelation = 'sLevel';
					options.pathRelation = 'sFID';
					options.directDeleteMode = true;
					options.limit = 10;
					
					options.onIndexChanging = null;
					options.onIndexChanged = Model.dataPersonIndexChanged;
					options.onBeforeNew = Model.dataPersonBeforeNew;
					options.onAfterNew = Model.dataPersonAfterNew;
					options.onBeforeDelete = Model.dataPersonBeforeDelete;
					options.onAfterDelete = Model.dataPersonAfterDelete;
					options.onValueChanged = Model.dataPersonValueChanged;
					options.onDataChanged = Model.dataPersonDataChanged;
					
					$scope.dataPerson = new BizData(options);

					//监视对象中的所有变动
					$scope.dataPerson.deregRows = $scope.$watch('dataPerson.rows',$scope.dataPerson.watchRows,true);//true代表深度监视，包括对象的属性，而不是简单的一个值
					//////////////////////////////////////////////
					
					//////////////////////对话框使用开始//////////////////////////////////////
					
			        //模态窗口打开之后执行的事件
			        $uibModalInstance.opened.then(function(){
			    		//接收调用对话框的参数
			    		Model.title = title;  
			    		Model.params = params;  
//						    		console.log('params-->',params);
//						    		if(params.id){
//						    			$scope.dataPerson.filter = "SaOpperson.sMainOrgID='"+params.id+"'";
//						    		}
//						    		$scope.dataPerson.refreshData();
			        });  
					
			        Model.ok = function () {  
				    	//保存成功
				    	//打包数据
				    	var event = {};
				    	var data = [];
				    	var sourceRow = $scope.dataPerson.rows[$scope.dataPerson.currentIndex];
				    	var row = {};
						//循环行中的列，判断变化点是哪一个
						for(var obj in sourceRow){
							if(obj!='$$hashKey' && obj!='userdata'){
								row[obj] = sourceRow[obj].value;
							}
						}
				    	
				    	data.push(row);
				    	event.data = data;
						$uibModalInstance.close(event);  
				    };  
				    
				    Model.cancel = function () {  
				        $uibModalInstance.dismiss('cancel');  
				    };    
					//////////////////////对话框使用结束//////////////////////////////////////
				    



					
					return Model;
				    
				    
				}])//控制器结束

				
	.controller('ognSelectSingleCtrl'
			,['$rootScope', '$scope', 'BizData', '$uibModalInstance','params', 'title'
			   , function ($rootScope, $scope, BizData, $uibModalInstance, params, title
			   ) {

					var Model = this;

					Model.gridRowClick = function(event){
						
					}

					Model.gridRowDblClick = function(event){
						Model.ok();
					}
					
					
					var options = {};
					options.container = Model;
					options.concept = 'SaOporg';
					options.name = 'dataList';
					options.url = $rootScope.path;
//					options.httpUrl = $rootScope.appConfigParams.resourceServer;
					options.httpUrl = $rootScope.getServiceName();
					options.reader = '/remote/org/tree/query';
					options.writer = '';
					options.deleter = '';
					options.idColumnDefine = "sID";
					options.idColumnName = "sID";
					options.isTree = false;
					options.parentRelation = 'sParent';
					options.nodeKindRelation = 'sNodeKind';
					options.nodeLevelRelation = 'sLevel';
					options.nodeSortRelation = "sSequence";
					options.pathRelation = 'sFID';
					options.directDeleteMode = false;
					options.limit = 10;
					
					Model.dataList = new BizData(options);

					//监视对象中的所有变动
					Model.dataList.deregRows = $scope.$watch('Model.dataList.rows',Model.dataList.watchRows,true);//true代表深度监视，包括对象的属性，而不是简单的一个值
					//////////////////////////////////////////////
					//增加过滤条件
					Model.dataList.filter = "SaOporg.sOrgKindID='ogn'";
//								Model.dataList.refreshData();
					
					//////////////////////对话框使用开始//////////////////////////////////////
					
			        //模态窗口打开之后执行的事件
			        $uibModalInstance.opened.then(function(){
			    		//接收调用对话框的参数
			    		Model.title = title;  
			    		Model.params = params;  

//						    		Model.dataList.refreshData();
			        });  
					
			        Model.ok = function () {  
				    	//保存成功
				    	//打包数据
				    	var event = {};
				    	var data = [];
				    	var sourceRow = Model.dataList.rows[Model.dataList.currentIndex];
				    	var row = {};
						//循环行中的列，判断变化点是哪一个
						for(var obj in sourceRow){
							if(obj!='$$hashKey' && obj!='userdata'){
								row[obj] = sourceRow[obj].value;
							}
						}
				    	
				    	data.push(row);
				    	event.data = data;
						$uibModalInstance.close(event);  
				    };  
				    
				    Model.cancel = function () {  
				        $uibModalInstance.dismiss('cancel');  
				    };    
					//////////////////////对话框使用结束//////////////////////////////////////

				    return Model;
				    
				    
				}])//控制器结束

	.controller('orgSelectSingleCtrl'
			,['$rootScope', '$scope', 'BizData'
			  , '$uibModalInstance','params', 'title'
			   , function f($rootScope, $scope, BizData
					   , $uibModalInstance, params, title
			   ) {
		
			var Model = this;
			
			
			/**
			name:bizData#onAfterRefresh
			description: <b>[回调型事件]</b>业务数据刷新后
			@param {object} event 
			<br/><b>结构如下：</b>
			<xmp> 
			{
				"source" : 组件的js对象
				"limit" : 页大小, 
				"offset" : 偏移,
				"success" : 是否成功刷新
			}
			</xmp>	
			*/
			Model.dataOrgAfterRefresh = function(event){
				var dataTree = event.source;
				//展开第一个
				var rowID = dataTree.getCurrentID();
				if(rowID!=null){
					dataTree.expandRow(rowID);
				}
			}
			
			////////////////////////////////////////////////////////////////////////////////////////
			
			var options = {};
			options.container = Model;
			options.concept = 'SaOporg';
			options.name = 'dataOrg';
			options.url = $rootScope.path;
//			options.httpUrl = $rootScope.appConfigParams.resourceServer;
			options.httpUrl = $rootScope.getServiceName();
			options.reader = '/remote/org/tree/query';
			options.writer = '';
			options.deleter = '';
			options.idColumnDefine = "sID";
			options.idColumnName = "sID";
			options.isTree = true;
			options.parentRelation = 'sParent';
			options.nodeKindRelation = 'sNodeKind';
			options.nodeLevelRelation = 'sLevel';
			options.nodeSortRelation = "sSequence";
			options.pathRelation = 'sFID';
			options.directDeleteMode = false;
				options.limit = -1;
			options.orderBy = 'sSequence ASC';
			
			options.onAfterRefresh = Model.dataOrgAfterRefresh;
			
			$scope.dataOrg = new BizData(options);
			
			//监视对象中的所有变动
			$scope.dataOrg.deregRows = $scope.$watch('dataOrg.rows',$scope.dataOrg.watchRows,true);//true代表深度监视，包括对象的属性，而不是简单的一个值
			//////////////////////////////////////////////
			
			
			//////////////////////对话框使用开始//////////////////////////////////////
			
			//模态窗口打开之后执行的事件
			$uibModalInstance.opened.then(function(){
				//接收调用对话框的参数
				Model.title = title;  
				Model.params = params;  
				console.log('params-->>',Model.params);
				//增加过滤条件
				$scope.dataOrg.filter = "SaOporg.sFID like '%"+Model.params.id+"%'";
			//	$scope.dataOrg.filter = "SaOporg.sCreatorFID = '" + Model.params.id + "'";
				if(Model.params.psm==false){
					$scope.dataOrg.filter = $scope.dataOrg.filter + " AND SaOporg.sOrgKindID<>'psm'"
				}
				if(Model.params.pos==false){
					$scope.dataOrg.filter = $scope.dataOrg.filter + " AND SaOporg.sOrgKindID<>'pos'"
				}
				$scope.dataOrg.refreshData();
			
			});  
			
			//
			Model.okValid = function () {  
				if(Model.params.validPsm==true && $scope.dataOrg.getCurrentIndex()>=0){
					//强检测是否为人员成员
					//console.log($scope.dataOrg.rows[$scope.dataOrg.getCurrentIndex()]);
					if($scope.dataOrg.rows[$scope.dataOrg.getCurrentIndex()].sOrgKindID.value=='psm'){
						return true;
					}else{
						return false;
					}
				}else{
					return true;
				}
			};
			
			Model.ok = function () {  
				//保存成功
				//打包数据
				var event = {};
				var data = [];
				
				var sourceRow = $scope.dataOrg.rows[$scope.dataOrg.currentIndex];
				var row = {};
				//循环行中的列，判断变化点是哪一个
				for(var obj in sourceRow){
					if(obj!='$$hashKey' && obj!='userdata'){
						row[obj] = sourceRow[obj].value;
					}
				}
				
				data.push(row);
				
				event.data = data;
				$uibModalInstance.close(event);  
			};  
			
			
			Model.cancel = function () {  
			    $uibModalInstance.dismiss('cancel');  
			};    
			
			return Model;
		
		}])//控制器结束

	.controller('cloudItemSelectMultiCtrl',
			['$rootScope', '$scope', 'BizData', '$uibModalInstance', 'params', 'title'
				, function f($rootScope, $scope, BizData, $uibModalInstance, params, title) {

				var Model = this;

				/**
				 * name:bizData#onAfterRefresh description: <b>[回调型事件]</b>业务数据刷新后
				 * 
				 * @param {object}
				 *            event <br/><b>结构如下：</b> <xmp> { "source" : 组件的js对象 "limit" :
				 *            页大小, "offset" : 偏移, "success" : 是否成功刷新 } </xmp>
				 */
				Model.dataMasterAfterRefresh = function(event) {
					var sActions = Model.params.sActions;
					if (sActions != null) {
						// 循环data
						for (var i = 0; i < Model.dataMaster.rows.length; i++) {
							var action = Model.dataMaster.rows[i].actionCode.value;
							if (sActions.indexOf(action) != -1) {
								Model.dataMaster.rows[i].userdata.checked = true;
							}
						}

					}
				}

				var options = {};
				options.container = Model;
				options.concept = 'CloudItem';
				options.name = 'dataMaster';
				options.url = $rootScope.path;
//				options.httpUrl = $rootScope.appConfigParams.resourceServer;
				options.httpUrl = $rootScope.getServiceName();
				options.reader = '/remote/cloudItem/list/query';
				options.writer = '';
				options.deleter = '';
				options.idColumnDefine = "fID";
				options.idColumnName = "fID";
				options.isTree = false;
				options.parentRelation = 'sParent';
				options.nodeKindRelation = 'sNodeKind';
				options.nodeLevelRelation = 'sLevel';
				options.nodeSortRelation = "sSequence";
				options.pathRelation = 'sFID';
				options.directDeleteMode = false;
				options.limit = 10;

				options.onAfterRefresh = Model.dataMasterAfterRefresh;

				Model.dataMaster = new BizData(options);

				// 监视对象中的所有变动
				// Model.dataMaster.deregRows =
				// $scope.$watch('Model.dataMaster.rows',Model.dataMaster.watchRows,true);//true代表深度监视，包括对象的属性，而不是简单的一个值
				// ////////////////////////////////////////////

				// ////////////////////对话框使用开始//////////////////////////////////////

				// 模态窗口打开之后执行的事件
				$uibModalInstance.opened.then(function() {
					// 接收调用对话框的参数
					$scope.title = title;
					Model.params = params;

//								Model.dataMaster.filter = "SysAction.systemFullID = '" + params.id + "'";
					Model.dataMaster.refreshData();

				});

				Model.ok = function() {
					// 保存成功
					// 打包数据
					var event = {};
					var data = [];

					// 循环data
					for (var index = 0; index < Model.dataMaster.rows.length; index++) {
						if (Model.dataMaster.rows[index].userdata.checked) {

							var sourceRow = Model.dataMaster.rows[index];
							var row = {};
							// 循环行中的列，判断变化点是哪一个
							for ( var obj in sourceRow) {
								if (obj != '$$hashKey' && obj != 'userdata') {
									row[obj] = sourceRow[obj].value;
								}
							}

							data.push(row);

						}
						
					}

					event.data = data;
					console.log('data-->',data);

					$uibModalInstance.close(event);
				};

				Model.cancel = function() {
					$uibModalInstance.dismiss('cancel');
				};

				// 表格标题中的选择对话框ng-model
				$scope.checkboxValue = false;
				// 表格标题中的选择对话框click事件
				Model.checkboxClick = function() {
					for (var index = 0; index < Model.dataMaster.rows.length; index++) {
						Model.dataMaster.rows[index].userdata.checked = $scope.checkboxValue;
					}
				};
				// ////////////////////对话框使用结束//////////////////////////////////////

				return Model;

			}])// 控制器结束
	.controller('expressTrackMonitorCtrl'
			,['$rootScope', '$scope', 'BizData', '$uibModalInstance','params', 'title', '$http', '$sce'
			   , function ($rootScope, $scope, BizData, $uibModalInstance, params, title, $http, $sce) {

					var Model = this;

					//////////////////////对话框使用开始//////////////////////////////////////
					
			        //模态窗口打开之后执行的事件
			        $uibModalInstance.opened.then(function(){
			    		//接收调用对话框的参数
			            Model.title = title;  
			            Model.params = params;  
			            var options = params;
//						            console.log('options-->',options);
			            
			            $http({
							method : 'POST'
							,url : $rootScope.getServiceName() + '/third/expressTrack/expressTrack'
							,data:  JSON.stringify(options)
						}).success(function(data){
							//console.log('快递查询.data-->',data);
							if(data.code==0){
								$scope.dataExpress = data.data;
								$scope.info = data.info;
							}else{
								$scope.info = "供应商api调用失败！";
							}
							/*
							$scope.expressTrack = {};
							$scope.expressTrack.resultStatus = data.resultStatus;
							if(data.resultStatus=='OK'){
								$scope.expressTrack.resultUrl = $sce.trustAsResourceUrl(data.resultUrl);
							}else{
								$scope.expressTrack.resultUrl = 'js/_services_api/tpl/expressTrack/expressTrack.html';
							}
							*/
						});
			            
			        });  
					
				    
				    Model.cancel = function () {  
				        $uibModalInstance.dismiss('cancel');  
				    };    
					//////////////////////对话框使用结束//////////////////////////////////////
					
					return Model;
				    
				}])//控制器结束
			    	

				
				
});